<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陆</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <script src="layui/layui.js"></script>
</head>
<body>
<form class="layui-form" id="loginForm"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" width="80px" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="password" width="80px" name="password" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="loginFilter">立即登陆</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
</form>
<!--layui代码-->
<script>
    layui.use(['form'],function () {
        var form = layui.form;
        var $ = layui.$;
        form.on('submit(loginFilter)',function () {
            $.ajax({
                url:'user/login',
                data:$('#loginForm').serialize(),
                success:function (result) {
                    if(result.flag){
                        if(result.admin==0){
                            location.href='product.html';
                        }else if(result.admin==1){
                            location.href='product2.html';
                        }
                    }else{
                        location.href='login.html';
                    }
                }
            })
            return false;
        })
    })
</script>
</body>
</html>